from django.db import models

from django.contrib.auth import get_user_model

# 从系统中获取自己定义的user表
User = get_user_model()


class MessageModel(models.Model):
    """
    消息模型
    """
    choice_type = (
        ('system_message', '系统消息'),
        ('user_attention', '用户关注'),
        ('blogs_were_like', '博客被喜欢'),
        ('user_questions', '用户提问')
    )
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    title = models.CharField(max_length=100, null=False, blank=False, verbose_name='消息标题')
    type = models.CharField(max_length=30, choices=choice_type, default='system_message', verbose_name='消息类型')
    content = models.CharField(max_length=300, null=False, blank=False, verbose_name='消息内容')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '消息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title
